package com.yanqu.road.server.timer.union;

import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.manager.union.CrossUnionParergonMgr;
import com.yanqu.road.utils.LocalDateTimeHelper;
import com.yanqu.road.utils.executor.GeneralTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class CrossUnionDailyResetTask extends GeneralTask {

    private Logger logger = LogManager.getLogger(this.getClass().getName());

    private long lastCheckTime = LocalDateTimeHelper.getZeroTimeTimeStamp();

    private boolean isRun = false;

    @Override
    public void doRun() {
        // 每天重新加载活动
        long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp();
        if(lastCheckTime < zeroTime && !isRun){
            isRun = true;
            logger.info("商会每日重置开始");
            try {
                CrossUnionMgr.resetOneDay();
                CrossUnionParergonMgr.resetDay();
                lastCheckTime = zeroTime;
                logger.info("商会每日重置结束");
            }catch (Exception e){
                logger.error("union reset error:", e);
            }finally {
                isRun = false;
            }
        }
    }
}
